package org.phantom.demo.mp3;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.phantom.demo.api.SearchBean;
import org.phantom.demo.api.SearchHandler;
import org.phantom.demo.api.SearchParameter;
import org.springframework.stereotype.Service;

/**
 * Hello world!
 *
 */
@Service("mp3SearchHandler")
public class Mp3SearchHandler implements SearchHandler{

	private List<Mp3> list = null;
	
	@PostConstruct
	public void init(){
		list = new ArrayList<Mp3>();;
		list.add(new Mp3("a","a"));
		list.add(new Mp3("b","b"));
		list.add(new Mp3("c","c"));
		list.add(new Mp3("d","d"));
		list.add(new Mp3("e","e"));
	}
	
	@Override
	public List<? extends SearchBean> doSearch(SearchParameter parameter) {
		List<Mp3> temp = new ArrayList<Mp3>();
		for (Mp3 mp3 : list) {
			if(mp3.getName().startsWith(parameter.getSearchValue().toString()))
				temp.add(mp3);
		}
		return temp;
	}
}
